﻿using System;
using CRM.Models.Email;

namespace CRM.ViewModels.Email
{
    public class EmailConfigVM
    {
        public EmailConfigVM(EmailConfig.EmailTypeEnum emailType)
        {
            EmailType = emailType;
        }
        public int Id { get; set; }
        public int UserId { get; set; }
        public int OemId { get; set; }
        public int CompanyId { get; set; }
        public int GroupId { get; set; }
        public string Name { get; set; }
        public string Driver { get; set; }
        public string Host { get; set; }
        public int? Port { get; set; }
        public int EmailConfigGroupId { get; set; }
        public string EmailAddress { get; set; }
        public EmailConfig.EmailTypeEnum EmailType { get; set; }
        public string Secret { get; set; }
        public bool Ssl { get; set; }
        public int MaxLastDaySendNum { get; set; }
        public EmailVerification State { get; set; } = EmailVerification.Unverified;
        public EmailConfig NewModel(Models.User user)
        {
            return new()
            {
                UserId = user.Id,
                OemId = user.OemId,
                CompanyId = user.CompanyId,
                GroupId = user.GroupId,
                Name = Name,
                Driver = Driver,
                Host = Host,
                Port = Port ?? 0,
                EmailAddress = EmailAddress,
                Secret = Secret,
                EmailConfigGroupId = 0,
                EmailType = EmailType,
                State = State,
                CreatedAt = DateTime.Now,
                Ssl = Ssl,
                MaxLastDaySendNum = MaxLastDaySendNum,
            };
        }
    }
}